import { writeFile, readFile } from '../api'
import { ElMessage } from 'element-plus'
export type Callback = () => void;
const useFile = () => {
    const getFile = (filename: string) => {
        return readFile(filename)
    }
    const saveFile = (filename: string, data: any, callback?: Callback) => {
        writeFile({ name: filename, data }).then(() => {
            ElMessage({
                message: '文件保存成功',
                type: 'success',
            })
            if (callback) {
                callback()
            }
        }).catch(() => {
            ElMessage({
                message: '文件保存失败',
                type: 'error',
            })
        })
    }
    return {
        getFile,
        saveFile
    }
}
export default useFile